package com.tql.mall.boss.controller.boss;

import com.tql.mall.boss.service.BaseAttrInfoService;
import com.tql.mall.boss.service.BaseAttrValueService;
import com.tql.mall.common.result.R;
import com.tql.mall.model.product.BaseAttrInfo;
import com.tql.mall.model.product.BaseAttrValue;
import com.tql.mall.model.product.BaseAttrValueQueryVo;
import com.tql.mall.model.product.BaseCategoryView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(description = "商品属性接口")
@RestController
@RequestMapping("/boss/boss/category/baseAttr")
public class BaseAttrController {

    @Autowired
    private BaseAttrValueService baseAttrValueService;
    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    /**
     * 根据描述完整商品分类信息的baseCategoryView对象获取该类商品的所有商品属性（商品属性当中包含了一系列商品属性值）
     * @param baseCategoryView
     * @return
     */
    //这个接口待修改
    @ApiOperation("根据商品完整分类对象BaseCategoryView获取该商品的商品属性(包含属性值)")
    @GetMapping("/getBaseAttrInfoVoList")
    public R<List<BaseAttrInfo>> BaseAttrInfoList(BaseCategoryView baseCategoryView){
        List<BaseAttrInfo> list = baseAttrInfoService.getListByBaseCategoryView(baseCategoryView);
        return R.ok(list);
    }

//    @ApiOperation("根据商品的分类id以及分类层级获取该分类下的平台属性(不包含属性值)")
//    @GetMapping("/getAttrList/{level}/{id}")
//    public R getAttrListByLevelAndId(@PathVariable Integer level,@PathVariable Long id){
//        List<BaseAttrInfo> list = baseAttrInfoService.getAttrListByLevelAndId(level,id);
//        return R.ok(list);
//    }
    @ApiOperation(value = "根据三级分类id得到该商品的属性列表（包含属性值）")
    @GetMapping("/getAttrList/{category3Id}")
    public R<List<BaseAttrInfo>> getAttrList(@PathVariable Long category3Id){
        List<BaseAttrInfo> list = baseAttrInfoService.getAttrList(category3Id);
        return R.ok(list);
    }



    @ApiOperation(value = "条件查询：获得属性值列表")
    @GetMapping("/getAttrValueList")
    public R<List<BaseAttrValue>> getAttrValueList(BaseAttrValueQueryVo baseAttrValueQueryVo){
        List<BaseAttrValue> list = baseAttrValueService.getAttrValueList(baseAttrValueQueryVo);
        return R.ok(list);
    }
    @ApiOperation(value = "根据属性值id获取BaseAttrInfo对象")
    @GetMapping("/getBaseAttrInfo/{id}")
    public R<BaseAttrInfo> getAttrInfo(@PathVariable Long id){
        BaseAttrInfo baseAttrInfo = baseAttrInfoService.getById(id);
        return R.ok(baseAttrInfo);
    }
    @ApiOperation(value = "修改属性值")
    @PutMapping("/updateAttrValue/{id}/{newName}")
    public R<Object> updateAttrValue(@PathVariable Long id,@PathVariable String newName){
        String msg = baseAttrValueService.updateAttrValue(id,newName);
        if (msg == null) return R.ok();
        return R.fail().msg(msg);

    }
    @ApiOperation(value = "添加属性值")
    @PostMapping("/addAttrValue")
    public R<Object> addAttrValue(String name, Long attrId){
        String msg = baseAttrValueService.addAttrValue(attrId,name);
        if (msg == null) return R.ok();
        return R.fail().msg(msg);
    }
    @ApiOperation(value = "删除属性值")
    @DeleteMapping("/deleteAttrValue/{id}")
    public R<Void> deleteAttrValue(@PathVariable Long id){
        baseAttrValueService.removeById(id);
        return R.ok();
    }
}
